const query = require("../config/db")
var express = require("express")
var router  = express.Router()

router.post("/create_order",async(req,res,next)=>{
    let {mid,cid,createdate} = req.body
    let sql2 = `select * from e_order where mid = '${mid}' and cid = '${cid}'`
    let result2 = await query(sql2)
    if(result2.length>0){
        next("该用户已经报名该课程")
        return
    }

    let oid=new Date().getTime()+(Math.random()+'').substr(2,6)
    let sql = `insert into e_order (oid,mid,cid,createdate,status) values ('${oid}','${mid}','${cid}','${createdate}','1')`
    let result = await query(sql)
    if(result.affectedRows>0){
        res.send({
            success:true,
            msg:"报名成功",
            status:200
        })
    }else{
        next("服务器出故障了⊙·⊙")
    }
})



module.exports = router